/**
 * 
 */
package com.geezdata.cps.ttk.api;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.PropertySource;

import com.geezdata.cps.base.aop.LoggerInterceptor;
import com.geezdata.cps.base.exceptions.handler.MyUncaughtExceptionHandler;
import com.geezdata.cps.cqrs.command.bus.CommandBus;
import com.geezdata.cps.cqrs.command.bus.impl.DefaultCommandBus;
import com.geezdata.cps.sdk3rd.pinduoduo.PinduoduoClient;
import com.geezdata.cps.sdk3rd.pinduoduo.PinduoduoDefaultClient;
import com.geezdata.cps.sdk3rd.wechat.WechatClient;
import com.geezdata.cps.sdk3rd.wechat.WechatDefaultClient;
import com.geezdata.cps.ttk.core.TtkCoreApplicationContext;
import com.geezdata.cps.ttk.query.TtkQueryApplicationContext;

/**
 * @author sszheng
 * @date 创建时间：2018年3月26日 下午5:04:38
 *
 */
@SpringBootApplication
@EnableAspectJAutoProxy
@ComponentScan(basePackages = {"com.geezdata.cps.ttk.api", "com.geezdata.cps.base.aop", "com.geezdata.cps.base.config"})
@EnableCaching
@Import(value = {
		TtkCoreApplicationContext.class,
		TtkQueryApplicationContext.class
})
@PropertySource(value = {
        "classpath:ttk-api-env.properties",
        "classpath:ttk-api-base.properties"
})	
public class TtkApiApplication extends SpringBootServletInitializer {
	private final static Logger logger = LoggerFactory.getLogger(TtkApiApplication.class);
	
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(TtkApiApplication.class);
    }
    
    public static void main(String[] args) throws Exception {
    	Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler());
    	SpringApplication.run(TtkApiApplication.class, args);
    	logger.info("============= SpringBoot Start Success =============");
    }
    
    @Bean
    public LoggerInterceptor loggerInterceptor() {
        LoggerInterceptor loggerInterceptor = new LoggerInterceptor();
        return loggerInterceptor;
    }
    
    @Bean
    public CommandBus commandBus() {
        return new DefaultCommandBus();
    }
    
    @Bean
    public WechatClient wechatClient() {
    	return new WechatDefaultClient();
    }
    
    @Bean
    public PinduoduoClient PinduoduoClient() {
    	return new PinduoduoDefaultClient();
    }
}
